
clear all
                                                                                                          
set more off     

set memory 10G
set matsize 10000
set maxvar  20000
set scrollbufsize 500000

cd "F:\TDriveCopy\Research\Nikhil\CreditLimit\Revision\Data\"

**** Dataset created in Revision/Code/getSTWFVars_Call.sas ****
use CallDataForBanks, clear

/*** 
	Note: In an intermediate step, which has been omitted from this code due to confidentiality reasons, CallDataForBanks.dta was merged 
	with the bank names from our credit bureau data. We focus on only credit card-issuing banks. Please see the data section of the paper for more details. 
	Subsequently, in the merged dataset, banks are ranked based on asset size. This bank rank is denoted by the variable "rank" which is utilized in the code below. 
	The variable "rank" identifies the banks in our sample uniquely.  
***/

keep if ctrl_ind==1 // i.e., Parent completely controls sub.
keep if charter==200 // commercial banks
format date %12.0g

duplicates drop

drop cert reln_lvl ctrl_ind reg_ind reg_high_hold location zipcode state insured charter // dropping unnecessary variables.

duplicates drop ultimaterssd_id id_rssd_offspring date, force // 0 dups.

// Collapsing to Parent level by summing up variables (there are no ratios among the variables).
local sumvarslist tot_assets tot_loans_gross deposits foreigndep demanddep transdep brokereddep brokereddeplt100k brokereddepge100k timedepge100k timedeplt100k cdge100k timedepgt250k timedeple250k brokereddeplt100k_lt1yr brokereddepge100k_lt1yr timedepge100k_lt1yr foreigntimedep_lt1yr fedfundspur repos tradingliab_exclreval fedfundsrepoliab tradingliabilities otherborrowedmoney otherborrowedmoney_lt1yr otherborrowedmoney_gt1yr tier1_cap tier2_cap tot_risk_based_cap excess_allow_loan_loss net_risk_wt_assets average_total_assets chargeoffs provision_loans_losses alloc_trans_risk_reserves alw_loan_leases_losses net_income equity_capital cash govsec nonperf_loans unused_cc_commit cc_sold_sec tot_cc_loans mortgage_loans tot_liabilities

local lastvarlist bankname bank_id

collapse (last) `lastvarlist ' (sum) `sumvarslist', by(rank ultimaterssd_id date year month)

duplicates drop rank date, force // 0 dups.

save AggregatedCallDataToBHCLvl, replace
